//
//  CellForImg.m
//  HYHoney
//
//  Created by dllo on 16/2/26.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CellForImg.h"
#import "ModelForZX.h"
#import "UIImageView+WebCache.h"
#import "DKNightVersion.h"

@implementation CellForImg

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self createVC];
    }
    return self;
}


- (void)createVC{

    self.width = [[NSString alloc] init];
    self.height = [[NSString alloc] init];
    
    self.imageZX = [[UIImageView alloc] init];
    [self.contentView addSubview:self.imageZX];
    
    [self pinch];
}



#pragma mark - 捏合(缩放)

- (void)pinch {
    
    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)];
    [self.imageZX addGestureRecognizer:pinch];
    [pinch release];
}

-(void)pinchAction:(UIPinchGestureRecognizer *)pinch{
    
    /** 修改 self.imageView 的transform属性 */
    NSLog(@"%f",pinch.scale);
    
    pinch.view.transform = CGAffineTransformScale(pinch.view.transform, pinch.scale, pinch.scale);
    
    /** 缩放因子归 1 */
    pinch.scale = 1;
    
}


- (void)layoutSubviews{

    [super layoutSubviews];
    
    self.imageZX.frame = CGRectMake((self.contentView.frame.size.width - 300) / 2, 50, 300, [self.height floatValue] / [self.width floatValue] * 300);
    self.imageZX.userInteractionEnabled = YES;

}



+ (CGFloat)heightForCellZX:(ModelForZX *)modelZX{

    CGFloat height2 = [modelZX.height floatValue] / [modelZX.width floatValue] * 300;
    
    return height2 + 100;
}



- (void)passModelZX:(ModelForZX *)model{
    
    NSLog(@"---%@---", model);
        
    [self.contentView addSubview:self.imageZX];
    
    self.width = model.width;
    self.height = model.height;
    self.url = model.thumbnail;
    
//    self.imageZX.frame = CGRectMake((self.contentView.frame.size.width - 300) / 2, 100, 150, [self.height floatValue] / [self.width floatValue] * 300);
    [self.imageZX sd_setImageWithURL:[NSURL URLWithString:self.url] placeholderImage:[UIImage imageNamed:@"jzz"]];
    
}


- (void)dealloc{

    [_imageZX release];
    [_height release];
    [_width release];
    [_url release];
    [super dealloc];
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
